<%@ page import="com.xpy.utils.ConnSqlServer" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String[] selectedAdminIds = request.getParameterValues("selectedAdmin");
    if (selectedAdminIds != null && selectedAdminIds.length > 0) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = ConnSqlServer.getConnection();
            String sql = "DELETE FROM admin WHERE id IN (";
            for (int i = 0; i < selectedAdminIds.length; i++) {
                sql += "?";
                if (i < selectedAdminIds.length - 1) {
                    sql += ",";
                }
            }
            sql += ")";
            pstmt = conn.prepareStatement(sql);
            for (int i = 0; i < selectedAdminIds.length; i++) {
                pstmt.setInt(i + 1, Integer.parseInt(selectedAdminIds[i]));
            }
            int rowsAffected = pstmt.executeUpdate();
            response.sendRedirect("admin_admin.jsp?message=success");
        } catch (Exception e) {
            e.printStackTrace();
            response.sendRedirect("admin_admin.jsp?message=error");
        } finally {
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    } else {
        response.sendRedirect("admin_admin.jsp?message=noselection");
    }
%>